package com.xxx.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author blijojo
 * @date 2021/5/24
 */
@RestController
@Slf4j
public class HystrixController {

    @GetMapping("/hystrix/break")
    @HystrixCommand(defaultFallback = "defaultFallBack")
    public String testBreak(int id) {
        log.info("接收商品id为: " + id);
        if (id <= 0) {
            throw new RuntimeException("不合法!!!");
        }
        return "当前商品id: " + id;
    }

    public String tesBreakFallBack(int id) {
        return "当前数不合法: " + id;
    }

    public String defaultFallBack() {
        return "服务器忙!!!";
    }

}
